package com.ht.aems.fesmonitor.actions.comm;

import com.ht.aems.fesmodel.CommUnit;
import com.ht.aems.fesmodel.FesServer;
import com.ht.aems.fesmonitor.FesMonitor;
import com.ht.aems.swing.util.MyAction;

import javax.swing.*;
import java.awt.event.ActionEvent;

/**
 * Created by IntelliJ IDEA.
 *
 * @author Dong Shufeng
 *         Date: 2008-7-19
 */
public class StopComm extends MyAction {
    public void actionPerformed(ActionEvent e) {
        FesMonitor monitor = (FesMonitor) this.getAncestor();
        CommUnit unit = monitor.getSelectedCommUnit();
        if (unit == null)
            return;
        monitor.stopComm(unit);
    }

    public void update(AbstractButton source) {
        FesMonitor monitor = (FesMonitor) this.getAncestor();
        CommUnit unit = monitor.getSelectedCommUnit();
        if (unit != null) {
            try {
                FesServer server = monitor.getServer();
                if (server != null && server.isConnected(unit)) {
                    source.setEnabled(true);
                    return;
                }
            } catch (Exception e1) {
                monitor.setServer(null);
            }
        }
        source.setEnabled(false);
    }
}
